<?php
final class Controller_Album_Class extends Controller_Security{
    protected function Acquiescent(){
        $data=Database::GetRows('select * from app_album_class order by ID asc');
        Template::Assign('Data',$data);
        Template::Display('album/class/list.html');
    }

    protected function Add(){
        $action=Route::GetArguments('action');
        if('save'===$action){
            Database::Insert('app_album_class',array(
                'Name'=>$_POST['name'],
                'Cover'=>$_POST['cover']
            ));
            header('location:./?application=admin&controller=album_class');
        }
        else{
            Template::Display('album/class/add.html');
        }
    }

    protected function Edit(){
        $action=Route::GetArguments('action');
        if('save'===$action){
            $id=$_POST['id'];
            Database::UpdateRowsByValue('app_album_class','ID',$id,array(
                'Name'=>$_POST['name'],
                'Cover'=>$_POST['cover']
            ));
            Template::Assign('ID',$id);
            Template::Assign('Name',$_POST['name']);
            Template::Assign('Cover',$_POST['cover']);
            Template::Assign('AlertContainerDisplaySwitch','block'); //警告容器
            Template::Assign('AlertContent','修改成功');             //警告内容
            Template::Display('album/class/edit.html');
        }
        else{
            $data=Database::GetRowByValue('app_album_class','ID',Route::GetArguments('id'));
            Template::Assign('ID',$data['ID']);
            Template::Assign('Name',$data['Name']);
            Template::Assign('Cover',$data['Cover']);
            Template::Assign('AlertContainerDisplaySwitch','none'); //警告容器
            Template::Assign('AlertContent','');                    //警告内容
            Template::Display('album/class/edit.html');
        }
    }

    protected function Delete(){
        $id=Route::GetArguments('id');
        Database::DeleteRowsByValue('app_album_class','ID',$id);
        header('location:'.$_SERVER['HTTP_REFERER']);
    }

    protected function Upload(){
        list($filename,$error)=array(NULL,NULL);
        $up=new Uploader('file');
        $up->Size=20481212300*12;
        $up->Path=$GLOBALS['ApplicationConfig']['Path']['UploadAlbumCover'];
        $up->FileExtension=array('gif','jpg','png','bmp');
        $up->Execute();
        switch($up->ErrorCode){
            case Uploader::UPLOAD_ERR_OK:
                $filename=$up->Filename;
            break;
            case Uploader::UPLOAD_ERR_NO_FILE:
                $error='请上传文件。';
            break;
            case Uploader::UPLOAD_ERR_EXTENSION:
                $error='扩展名不正确。';
            break;
            case Uploader::UPLOAD_ERR_CUSTOM_SIZE:
                $error='文件大小不正确。';
            break;
            default:
                //$error=$up->ErrorCode;
                $error='上传失败';
            break;
        }
        Template::Assign('Filename',$GLOBALS['ApplicationConfig']['Path']['URIAlbumCover'].'/'.$filename);
        Template::Assign('Error',$error);
        Template::Display('upload/callback.html');
    }
}
?>